home *** CD-ROM | disk | FTP | other *** search
/ OpenGL Superbible (2nd Edition) / OpenGL SuperBible e2.iso / book / Chap08 / TEX2D / bitmap.h < prev    next >
Encoding:
C/C++ Source or Header  |  1999-09-27  |  3.2 KB  |  101 lines

  1. /*
  2.  * Windows BMP file definitions for OpenGL.
  3.  *
  4.  * Written by Michael Sweet.
  5.  */
  6.  
  7. #ifndef _BITMAP_H_
  8. #  define _BITMAP_H_
  9.  
  10. /*
  11.  * Include necessary headers.
  12.  */
  13.  
  14. #  include <GL/glut.h>
  15. #  ifdef WIN32
  16. #    include <windows.h>
  17. #    include <wingdi.h>
  18. #  endif /* WIN32 */
  19.  
  20. /*
  21.  * Make this header file work with C and C++ source code...
  22.  */
  23.  
  24. #  ifdef __cplusplus
  25. extern "C" {
  26. #  endif /* __cplusplus */
  27.  
  28.  
  29. /*
  30.  * Bitmap file data structures (these are defined in <wingdi.h> under
  31.  * Windows...)
  32.  *
  33.  * Note that most Windows compilers will pack the following structures, so
  34.  * when reading them under MacOS or UNIX we need to read individual fields
  35.  * to avoid differences in alignment...
  36.  */
  37.  
  38. #  ifndef WIN32
  39. typedef struct                       /**** BMP file header structure ****/
  40.     {
  41.     unsigned short bfType;           /* Magic number for file */
  42.     unsigned int   bfSize;           /* Size of file */
  43.     unsigned short bfReserved1;      /* Reserved */
  44.     unsigned short bfReserved2;      /* ... */
  45.     unsigned int   bfOffBits;        /* Offset to bitmap data */
  46.     } BITMAPFILEHEADER;
  47.  
  48. #  define BF_TYPE 0x4D42             /* "MB" */
  49.  
  50. typedef struct                       /**** BMP file info structure ****/
  51.     {
  52.     unsigned int   biSize;           /* Size of info header */
  53.     int            biWidth;          /* Width of image */
  54.     int            biHeight;         /* Height of image */
  55.     unsigned short biPlanes;         /* Number of color planes */
  56.     unsigned short biBitCount;       /* Number of bits per pixel */
  57.     unsigned int   biCompression;    /* Type of compression to use */
  58.     unsigned int   biSizeImage;      /* Size of image data */
  59.     int            biXPelsPerMeter;  /* X pixels per meter */
  60.     int            biYPelsPerMeter;  /* Y pixels per meter */
  61.     unsigned int   biClrUsed;        /* Number of colors used */
  62.     unsigned int   biClrImportant;   /* Number of important colors */
  63.     } BITMAPINFOHEADER;
  64.  
  65. /*
  66.  * Constants for the biCompression field...
  67.  */
  68.  
  69. #  define BI_RGB       0             /* No compression - straight BGR data */
  70. #  define BI_RLE8      1             /* 8-bit run-length compression */
  71. #  define BI_RLE4      2             /* 4-bit run-length compression */
  72. #  define BI_BITFIELDS 3             /* RGB bitmap with RGB masks */
  73.  
  74. typedef struct                       /**** Colormap entry structure ****/
  75.     {
  76.     unsigned char  rgbBlue;          /* Blue value */
  77.     unsigned char  rgbGreen;         /* Green value */
  78.     unsigned char  rgbRed;           /* Red value */
  79.     unsigned char  rgbReserved;      /* Reserved */
  80.     } RGBQUAD;
  81.  
  82. typedef struct                       /**** Bitmap information structure ****/
  83.     {
  84.     BITMAPINFOHEADER bmiHeader;      /* Image header */
  85.     RGBQUAD          bmiColors[256]; /* Image colormap */
  86.     } BITMAPINFO;
  87. #  endif /* !WIN32 */
  88.  
  89. /*
  90.  * Prototypes...
  91.  */
  92.  
  93. extern GLubyte *LoadDIBitmap(const char *filename, BITMAPINFO **info);
  94. extern int     SaveDIBitmap(const char *filename, BITMAPINFO *info,
  95.                             GLubyte *bits);
  96.  
  97. #  ifdef __cplusplus
  98. }
  99. #  endif /* __cplusplus */
  100. #endif /* !_BITMAP_H_ */
  101.